package ks.managers.icon;

import java.net.URL;
import java.util.Collection;
import java.util.Hashtable;

/**
 * Manages a set of icons.
 * <p>
 * This manager can be used on either client or server.
 * 
 * @author George Heineman
 */
public class IconManager {
	
	/** Store icons in memory. */
	protected Hashtable<String, Icon> knownIcons = new Hashtable<String, Icon>();
	
	/** Protect access to this constructor. */
	public IconManager() {}
	
	/** Clear away all icons. */
	public void removeAll() {
		knownIcons = new Hashtable<String, Icon>();
	}
	
	/**
	 * Adds the given Icon by name and URL to be associated with that icon.
	 * <p>
	 * 
	 * @param iconName
	 * @param url
	 */
	public boolean add (String iconName, URL url) {
		// associate Icon with this name.
		Icon icon = new Icon (iconName, url);
		knownIcons.put(iconName, icon);
		
		// done
		return true;
	}
	
	/** 
	 * Determine if icon exists.
	 * <p>
	 * Return Icon entity object or null if no such object exists in our storage.
	 * 
	 * @param name
	 */
	public Icon getIcon (String name) {
		return knownIcons.get(name);
	}
	
	/**
	 * Return a collection of Strings representing known icons in this manager.
	 */
	public Collection<Icon> getList() {
		return knownIcons.values();
	}
}
